Skip to content

Fix log in iOS11 simulators. #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 13, 2017
Merged

Conversation

KristianDD
Copy link
Contributor

Part of the fix NativeScript/nativescript-cli#3141 (comment)

Fix uses the method described in this example.

lib/simctl.ts Outdated
@@ -120,11 +121,19 @@ export class Simctl implements ISimctl {
return devices;
}

public getLog(deviceId: string): any {
return this.simctlSpawn("spawn", [deviceId, "log", "stream"]);

This comment was marked as abuse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the great suggestions, NathanaelA!

I will add --style syslog as this will really make the log very similar to the one in Simulators with previous iOS versions.

I can't add --predicate 'senderImagePath contains "NativeScript" directly as this tool is not framework specific and is published as separate NPM package. I can however add an optional predicate argument to the method.

deviceLogChildProcess = this.getDeviceLogProcess(deviceId);
if (deviceLogChildProcess.stdout) {
deviceLogChildProcess.stdout.on("data", (data: NodeBuffer) => {
let dataAsString = data.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be const

if (deviceLogChildProcess.stderr) {
deviceLogChildProcess.stderr.on("data", (data: string) => {
let dataAsString = data.toString();
if (pid) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided that we log the data regardless of whether you enter the if or the else I'd suggest we remove the filter as a whole.
The code could be narrowed down to:

deviceLogChildProcess.stderr.on("data", (data: string) => {
    process.stdout.write(data.toString());
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with @rosen-vladimirov and actually the logging outside the if and else statements is a mistake. Will fix it.

}

public getDeviceLogProcess(deviceId: string): any {
return common.getDeviceLogProcess(deviceId);
const device = this.getDeviceFromIdentifier(deviceId) || {};
const deviceVersion = this.getDeviceFromIdentifier(deviceId).runtimeVersion || "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use device here
const deviceVersion = device.runtimeVersion || "";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad.

if(majorVersion && parseInt(majorVersion) >= 11) {
this.deviceLogChildProcess = this.simctl.getLog(deviceId);
} else {
let logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", deviceId, "system.log");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be const

}

public getDeviceLogProcess(deviceId: string): any {
return common.getDeviceLogProcess(deviceId);
const device = this.getDeviceFromIdentifier(deviceId) || {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initialization of these variables can be done inside the if statement down below, because they're only used there

lib/simctl.ts Outdated
return result.stdout.toString().trim();
}
return '';
}

private simctlSpawn(command: string, args: string[], opts?: any): any {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type here can be narrowed to child_process.ChildProcess instead of any

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, you can specify opts?: child_process.SpawnOptions instead of opts?: any

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

}

if (deviceLogChildProcess.stderr) {
deviceLogChildProcess.stderr.on("data", (data: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event handlers for deviceLogChildProcess.stderr.on("data" and deviceLogChildProcess.stdout.on("data" are identical - you can extract the handler as a separate function and pass it to both cases

lib/simctl.ts Outdated
@@ -120,11 +121,25 @@ export class Simctl implements ISimctl {
return devices;
}

public getLog(deviceId: string, predicate?: string): any {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type here is child_process.ChildProcess

}

public getDeviceLogProcess(deviceId: string): any {
return common.getDeviceLogProcess(deviceId);
public getDeviceLogProcess(deviceId: string, predicate?: string): any {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type here is child_process.ChildProcess

@@ -116,11 +120,64 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
}

public printDeviceLog(deviceId: string, launchResult?: string): any {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can change the return type to child_process.ChildProcess here as well

lib/simctl.ts Outdated
public getLog(deviceId: string, predicate?: string): any {
let predicateArgs: string[] = [];

if (!_.isUndefined(predicate)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a simple check like if (predicate) { would suffice here, but this is a personal preference

@KristianDD KristianDD force-pushed the kddimitrov/ios11-xcode9 branch from f9a812e to 56db899 Compare October 11, 2017 12:36
Copy link
Contributor

@Mitko-Kerezov Mitko-Kerezov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay to me

@KristianDD KristianDD force-pushed the kddimitrov/ios11-xcode9 branch from 56db899 to f2ccf13 Compare October 12, 2017 16:19
@Mitko-Kerezov Mitko-Kerezov merged commit 5153663 into master Oct 13, 2017
@Mitko-Kerezov Mitko-Kerezov deleted the kddimitrov/ios11-xcode9 branch October 13, 2017 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No console.log output Xcode 9 iOS 11
3 participants